﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AddDeadlineForm.cs" company="HelloWorld">
//   BY黄媛媛
// </copyright>
// <summary>
//   Defines the AddDeadlineForm type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace WindowsFormsApp2.Form
{
    using System;
    using System.Windows.Forms;

    using WindowsFormsApp2.Service;

    /// <summary>
    /// The add deadline form.
    /// </summary>
    public partial class AddDeadlineForm : Form
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AddDeadlineForm"/> class.
        /// </summary>
        /// <param name="weekday">
        /// The weekday.
        /// </param>
        /// <param name="chooseLesson">
        /// The choose lesson.
        /// </param>
        public AddDeadlineForm(int weekday, int chooseLesson)
        {
            this.InitializeComponent();
            this.Weekday = weekday;
            this.ChooseLesson = chooseLesson;
        }

        /// <summary>
        /// Gets the weekday.
        /// </summary>
        public int Weekday { get; }

        /// <summary>
        /// Gets the choose lesson.
        /// </summary>
        public int ChooseLesson { get; }

        /// <summary>
        /// The button 1_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void Submit_Click(object sender, EventArgs e)
        {
            if (this.taskTxt.Text == string.Empty)
            {
                MessageBox.Show(@"请输入任务名称");
                return;
            }

            if (this.dateTimePicker1.Value < DateTime.Now)
            {
                MessageBox.Show(@"日期不合法，请重新选择日期");
                return;
            }

            if (!new DDLManage().AddDDL(
                    this.Weekday,
                    this.ChooseLesson,
                    this.taskTxt.Text,
                    this.dateTimePicker1.Value.ToString("yyyy-MM-dd")))
            {
                MessageBox.Show(@"无课程，添加ddl失败");
            }

            this.Close();
        }

        /// <summary>
        /// The button 2_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
